package com.fang.system.rpc.handler;

import com.fang.system.rpc.callback.ResponseMappingCallback;
import com.fang.system.rpc.model.PackageMsg;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @author fanglingxiao
 * @version 1.0
 * @description TODO
 * @date 2022/7/16 6:21 下午
 **/
public class ClientResponse extends ChannelInboundHandlerAdapter {
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
        PackageMsg resPackageMsg = (PackageMsg) msg;
        ResponseMappingCallback.runCallback(resPackageMsg);
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        super.exceptionCaught(ctx, cause);
        if (ctx.channel().isActive()) {
            ctx.close();
        }
    }
}
